package com.wali.modules.usr.control;

import com.wali.common.ccp.exception.CcpException;
import com.wali.common.enums.ErrorCodeEnum;
import com.wali.common.web.BaseController;
import com.wali.modules.system.vo.SysUserVO;
import com.wali.modules.usr.bo.UsrSenderBO;
import com.wali.modules.usr.service.UsrSenderService;
import com.wali.modules.usr.vo.UsrSenderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author walixu
 * @ClassName com.wali.modules.usr.control
 * @Description 发件人controller类
 * @email wali.xu@kpmg.com
 * @date 22/01/2019 8:56 下午
 */
@Controller
@RequestMapping(value = "/usr")
public class UsrSenderController extends BaseController {

    @Autowired
    private UsrSenderService usrSenderService;

    /**
     * @param
     * @return
     * @throws
     * @Title listUsrSender
     * @Description 检索查询发件人列表
     */
    @RequestMapping(value = "/listUsrSender")
    public ResponseEntity<String> listUsrSender(HttpServletRequest request, UsrSenderBO usrSender) {
        int code = ErrorCodeEnum.ERROR_INTERNAL_CODE.getCode();
        String msg = ErrorCodeEnum.ERROR_INTERNAL_CODE.getMessage();

        try {
            logger.info(usrSender.toString());

//            HttpSession session = request.getSession(false);
//            SysUserVO sysUser = (SysUserVO) session.getAttribute("user");

//            usrSender.setUserId(sysUser.getId());
            List<UsrSenderVO> usrSenderList = usrSenderService.listUsrSender(usrSender);
            return getResponseEntity(ErrorCodeEnum.SUCCESS_CODE.getCode(), ErrorCodeEnum.SUCCESS_CODE.getMessage(), usrSenderList);
        } catch (CcpException e) {
            logger.error(e.getMessage(), e);
            code = e.getException().getCode();
            msg = e.getException().getMessage();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        return getResponseEntity(code, msg);

    }
}
